-- 传奇4



require("TSLib")
require('tsp')

-- w.input("27.124.25.15")
-- w.click(width-50,height-50)
-- w.input("20408")
-- w.click(161,858)
-- w.input("451fbd3e-bde6-4379-b27d-a8b3606abbe8")

_app={}
_app.game = "com.wemade.mir4global"
init(2)
t={}
degree = 80
t['事件-登录主页']={ {{435,650,0xe6d1b0},{818,295,0xb30101},{1233,641,0xc6cace}}, degree , 304,202,1318,690}
t['事件-职业选择']={ {{1192,681,0xdfb176},{1186,647,0xdda56c},{39,47,0xffffff},{50,47,0x374b8f}}, degree , 15,13,1316,732}
-- 1188,234,法师
t['事件-角色名']={ {{750,460,0xaec2de},{557,454,0xdeaeae},{687,270,0xb8c0d2},{819,460,0x263554}}, degree , 391,239,946,496}
-- 622,348，角色名
    t['事件-角色名-ok']={ {{519,273,0x007aff},{537,258,0x007aff}}, degree , 423,224,659,392}
t['事件-开始游戏']={ {{1172,685,0xdfb176},{1134,646,0xdda56c},{132,681,0xaec2de},{39,48,0xffffff}}, degree , 19,21,1313,732}

t['事件-初始移动向上']={{541, 443, 0xf6ba0e},{542, 453, 0xdfdfdf},{543, 452, 0x202020},{551, 464, 0xd3d2d0}}

t['弹窗-排队提示']={ {{722,501,0x493434},{679,228,0xc2c4cc},{877,226,0x282f41}}, degree , 376,205,961,541}
t['弹窗-剧情跳过']={ {{1277,57,0xd6d9dd},{1267,50,0x000000},{1262,64,0xfbfbfb},{1232,53,0xdfdfdf},{1231,53,0x0a0a0a}}, degree , 1181,32,1288,76}
t['弹窗-启动弹窗x']={ {{1193,640,0xffffff},{1180,627,0xfdfdfd},{1244,646,0x515354},{1279,650,0x4e4f52}}, degree , 1164,615,1312,670}
t['弹窗-指引任务']={ {{1221,187,0x27353b},{1215,150,0xbe9416},{1224,222,0xab7f1c}}, degree , 1166,117,1297,247}
t['弹窗-点击对话']={ {{1224,659,0xffffff},{1216,659,0x3099ab},{1232,659,0x1e6278}}, degree , 1174,619,1253,697}
t['弹窗-重新连接']={ {{635,475,0xaec2de},{666,480,0x263554},{662,457,0x263554},{681,246,0xb6bed0},{683,249,0x2e3648}}, degree , 556,223,785,518}


t['主界面-血条']={{16, 41, 0xa40303},{16, 42, 0xa40303},{16, 44, 0xa40303},{16, 45, 0xa40303},{16, 46, 0xa40303}}
t['大地图-退出']={ 0xebebeb, "0|0|0xebebeb,-16|-2|0xeeeeee,-13|657|0x112030",degree , 1250,8,1323,739}
t['小地图-退出']={ 0xe9e9e9, "0|0|0xe9e9e9,-9|-1|0x090f1a,-18|-3|0xeeeeee",degree , 1268,5,1323,59}

function UIres(t)
    for k,v in pairs(t) do
        if w.fc(k) then
            return k
        end
    end
end



t['小龙提示']={ 0xf5877e, "0|0|0xf5877e,8|-39|0xea5d4b,-45|-19|0xca3842,-4|11|0xd4bb60",degree,9,16,242,303}

function event()
    if w.fc('事件-开始游戏',true,1,5) then
    -- elseif w.fc('事件-职业选择') then
    --     w.click(1188,234)
    --     w.fc("事件-职业选择",true)
    elseif w.d("小龙提示")then
        if guard() then
            local xiaolong = {{1172, 186, 0x404946}}
            w.table_click(xiaolong)
        end
    elseif w.fc('事件-角色名') then
        w.click(622,348)
        name = w.myRand(3,w.rd(5,8))..w.myRand(1,w.rd(2,3))
        w.log(name)
        w.input(name,true)
        w.fc("事件-角色名-ok",true)
        w.fc("事件-角色名",true)
    elseif w.fc('事件-登录主页')then
        w.click(height/2,width/2,5)
    elseif w.mc("事件-初始移动向上") then
        moveTo(207,582,217,401)
    elseif w.d("大地图-退出",true) then
    elseif w.d("小地图-退出",true) then
    else
        return true
    end
end


t['弹窗-跳过>>'] = {{1262, 49, 0xf9f9fa},{1270, 47, 0xfcfcfc},{1268, 55, 0xcbd0d4}}
t['弹窗-前往登录']={ {{659,481,0xaec2de},{662,476,0x263554},{682,246,0xb6bed0},{678,242,0x2b3346}}, degree , 510,224,824,520}
t['弹窗-断开连接']={ {{648,467,0xa6bad6},{654,467,0x263554},{680,440,0x263554},{673,485,0x263554},{681,252,0xc2c4cc}}, degree , 558,239,764,506}
t['弹窗-取消自动']={ {{559,458,0xaec2de},{561,465,0x263554},{752,472,0x4d3737},{754,472,0xdeaeae},{714,262,0xc2c4cc},{715,270,0x2a3344}}, degree , 465,245,951,501}
t['弹窗-个人信息x']={ {{875,37,0xfefefe},{874,27,0x2b3244},{867,36,0x272d3e},{883,45,0xfcfdfd}}, degree , 852,16,898,56}
t['弹窗-活动x']={ 0xffffff, "0|0|0xffffff,0|-6|0x2a3142,11|-11|0xf1f1f2,10|9|0xebeced",degree , 1156,47,1196,88}
t['弹窗-任务x']={ 0xfcfcfd, "0|0|0xfcfcfd,9|-9|0xdbdde0,8|-2|0x2a3343,8|9|0xe8e8ea",degree , 1154,57,1200,101}
t['弹窗-广告取消']={ 0xffffff, "0|0|0xffffff,-431|538|0x493434,-37|532|0x263554",degree,390,76,937,656}
t['弹窗-全部菜单']={ 0xe8e8e9, "0|0|0xe8e8e9,-1226|644|0xbdc2c7,-1224|638|0x323d4a,-1224|623|0xb9bdc2",degree,0,3,1331,743}

function tips()
    if w.fc("弹窗-启动弹窗x",true) then
    elseif w.fc("弹窗-剧情跳过",true)then
    elseif w.fc("弹窗-指引任务",true)then
    elseif w.fc("弹窗-点击对话",true)then
    elseif w.fc("弹窗-重新连接",true)then
    elseif w.fc("弹窗-前往登录",true)then
    elseif w.fc("弹窗-取消自动",true,1,10)then
    elseif w.fc("弹窗-个人信息x",true)then
    elseif w.fc("弹窗-断开连接",true)then
    elseif w.d("弹窗-活动x",true)then
    elseif w.d("弹窗-委托-接受委托",true)then
    elseif w.d("弹窗-任务x",true)then
    elseif w.d("弹窗-广告取消",true)then
    elseif w.fc("提示-确认取消",true)then
        w.click(40,40)
    elseif w.d("弹窗-全部菜单",true) then
    elseif w.fc("弹窗-排队提示") then
        w.delay(3)
    else
        return true
    end
end


t['引导-轻功']={{1284, 427, 0xfbf980},{1278, 423, 0x502e20}}
t['引导-轻功2']={{1138, 536, 0xd28f02},{1150, 533, 0x5f3c32},{1152, 537, 0xd0ce12}}
t['引导-跳过>>']={{75, 45, 0xdfdfdf},{163, 45, 0xccd0d4},{220, 46, 0xaf0a0e}}
t['引导-向左移动']={{561, 454, 0xe3a705},{562, 464, 0xdfdfdf},{563, 463, 0x202020},{571, 473, 0x221306}}
t['引导-跳过>>2']={{94, 43, 0x130707},{96, 43, 0xdfdfdf},{149, 39, 0xf9f9fa},{157, 39, 0xebebeb}}
t['引导-学习']={ {{1011,689,0xcba16b},{1012,692,0x100706},{1037,726,0xf6e8af},{1070,667,0xdda56c}}, degree , 831,649,1155,738}
t['引导-强化']={ {{1123,699,0xdfb176},{1143,668,0xdda56c},{1129,727,0xf6e8af}}, degree , 901,651,1236,739}
t['引导-装备']={ {{750,578,0xaec2de},{762,558,0x384866},{561,582,0xdeaeae},{881,103,0xffffff}}, degree , 468,81,902,625}

t['引导-退出']={ {{1311,29,0xededed},{1296,18,0xfbfbfb},{1305,19,0x030911},{1304,40,0x030913}}, degree , 1281,8,1323,54}


function guard()
    if w.mc("引导-轻功",true) then
    elseif w.mc("引导-轻功2",true,3)then    
    elseif w.mc("弹窗-跳过>>",true,3)then
    elseif w.mc("引导-向左移动")then
        for i=0,10 do
            moveTo(203,559,82,552)
            moveTo(203,559,82,552)
        end
    elseif w.mc("引导-跳过>>",true,3)then
    elseif w.mc("引导-跳过>>2",true,1)then
        w.mc("引导-跳过>>2",true,1)
    elseif w.fc("引导-学习",true) then
    elseif w.fc("引导-强化",true) then
        w.fc("引导-退出",true)
    elseif w.fc("引导-装备",true) then
    elseif w.fc("引导-退出",true) then
    else
        return true
    end
end


--内容已复制到剪贴板!
local tab = {
"0610000c4601120c000622000800000d000c40781ff014040900404007138186009001820100@01$级$62$18$17",
"100000000002000fff@111$1$17$15$5",
"0002801c004c011804301050c09e01000@001$2$26$15$9",
"00048000040c081810304011211c3c$3$23$15$8",
"00600140088041010208043fff8010002@000$4$29$15$9",
"fe010406080c1018201020803e@0$5$26$15$7",
"00803ff080120000203040608140fc$6$29$15$8",
"80010002000c006807103023807800c00@000$7$24$15$9",
"003070d91204181810306051211c36003@000$8$36$15$9",
"0c007e05020c041808000090021ff8$9$30$15$8",
"03807ff10014001800300050011ffc$0$35$15$8",
"18403440e64327ff24422444000000037fff4903498249e2491849167f220001$银$90$16$16",
"108011801100133f16231c231823ffa3ffa318231c231623133f11001180$杏$88$16$15",
"00802100c6031ffc2c70d0c3218c431886190e1a1e1e341fe4300c20@0$谷$80$15$15",
"01002300273e252425242d243924f124f93c290129012d0125ff27fe2100$奇$89$16$15",
"00400088013ffe7f6ff24ee49949229245248a495493effcc0f9c011@1$县$99$15$15",
"ffffffff060206060606060400000000ffff0303020306030c03181f$比$84$16$14",
"00200c2018203620662006200620ffffffff062006206620362018200c20$半$77$16$15",
"00401f403f4f254be548654825483f483f4825486548e548254b3f4f0040$兽$96$16$15",
"1800180018ff18c318c218c218c2ffc2ffc218c218c218c218c718ff1800$古$91$16$15",
"404c40494f594f79f169f1e941c9415f415f4149f149f1694f794f594049$墓$113$16$15",
"3003001801fff$1$19$13$4",
"0007fffbff048009047249e49fc9399247248e4914922925de49fc90@1$层$101$15$15",
"01002300273e252425242d243924f124f93c29012901250125ff27fc2100$奇$87$16$15",
"0418446067c07fffc4c0046000e30306000ccfff607121c107013e0361c60060$秘$93$16$16",
"00802100c6031ffc3ff0d0c3218c431886190e1a1e1e341fe4300c20@0$谷$84$15$15",
"00060ffbff048009047249e49fc9399243248e4914922925da49fc10@1$层$93$15$15",
"3003001801fff$1$19$13$4",
"401a01f01f031c30bf04f0@001$2$34$13$7",
"401e006083041c61be9de7@110$3$36$13$7",
"01c01203106086047ffc01@000$4$28$13$7",
}

local index = addTSOcrDictEx(tab)
--请自行更改参数
--1: 0,0,0,0 范围坐标，请自行修改
--2: "FFEAAD , 0A0B0B" 偏色,多组或单组.请在偏色列表中选择
--3: 90 匹配精度 【0-100】

t['主界面-是队长']={0xf8d77c, "0|0|0xf8d77c,3|5|0x976536",degree,18,9,43,29}

function ocrLevel()
    levels = levels or 1
    if w.d("主界面-是队长") then
        ret = tsOcrText(index, 46,10,74,31, "FFEAAD , 0A0B0B", 90)
    else
        ret = tsOcrText(index, 10,10,60,31, "FFEAAD , 0A0B0B", 90)
    end
    w.log("识别到的内容:"..ret)
    if ret and string.len(ret) > 1 then
        ret = string.gsub(ret,'级','')
        w.log(ret)
        if not(type(tonumber(ret)) == 'number') then
            return 1
        else
            ret = tonumber(ret)
            if ret >= levels then
                levels = ret
                return ret
            else
                return levels
            end
        end
    else
        return levels
    end
    
end

function ocrMaps()
    local ret = tsOcrText(index, 1090,89,1250,119,  "FFFFFF , 050505 # E5E5E4 , 2A2B2B", 90)
    w.log("识别到的内容:"..ret)
    if ret then
        return ret
    end
end


t['主界面-主线任务']={ {{1192,169,0x97dcff},{1192,166,0x97dcff}}, degree , 1098,156,1261,212}
    t['主界面-接授任务']={ {{1238,454,0xa9d0d8},{1240,407,0x90c9ff},{1242,500,0x90c9ff}}, degree , 1163,102,1280,744}
    t['主界面-自动任务']={ {{1029,169,0xbabec7},{1025,158,0x2b3f67},{1022,194,0x50b6d2}}, degree , 975,139,1080,206}
        t['主界面-自动任务-顺序']={ {{182,157,0x2d333d},{182,135,0x272e3a},{183,169,0x272e3a}}, degree , 158,125,208,176}
        t['主界面-自动任务-开始']={ {{1089,643,0xadc1dd},{1097,616,0x384866},{1096,669,0x465675}}, degree , 1065,605,1127,684}
        
t['主界面-主线任务-激活态']={ {{1062,159,0xbeffff},{1061,157,0xffffff}}, degree , 1073,155,1090,172}
t['主界面-主线任务-到矿点']={ {{725,408,0xedfef5},{730,411,0x82e8e9}}, degree , 578,358,867,503}
    t['主界面-主线任务-挖矿']={ {{320,687,0xfefefe},{326,684,0x565454},{333,687,0xffffff},{337,699,0x575454}}, degree , 298,658,357,710}
    t['主界面-主线任务-正在战斗']={{407, 687, 0xf8fdfd},{412, 700, 0x2e94a2},{333, 687, 0xffffff},{337, 699, 0x575454}}
    
t['主界面-任务-一键领取']={ {{1193,171,0xb3d6d4},{1228,175,0x2c4c5d},{1230,172,0xb3d6d4}}, degree , 1177,157,1275,186}
t['主界面-正在跑路']={ {{815,550,0xdadad9},{818,557,0xeaebec},{816,565,0xf0f1f2}}, degree , 759,544,826,572}
t['主界面-正在自动任务中']={{1071, 239, 0xfbfbfd},{1071, 255, 0xdee1ec},{1109, 233, 0x589bbe}}

    t['主界面-任务-跳高']={ 0xeee813, "0|0|0xeee813,-1|-15|0x2e1f1d",degree,1263,417,1310,468}

function task_main()
    if w.fc("主界面-正在跑路") or w.mc('主界面-正在自动任务中') then
        w.delay(5)
    elseif w.fc('主界面-主线任务-激活态') or w.mc("主界面-主线任务-正在战斗")then
        task_active = task_active or 1
        task_active = task_active + 1
        if task_active%5 == 0 then
            w.fc("主界面-主线任务-挖矿",true,1,5)
        end
        if w.fc('主界面-主线任务-到矿点') then
            w.fc("主界面-主线任务-挖矿",true)
        end
    elseif w.fc('主界面-主线任务',true,1,3) then
        if w.fc("主界面-任务-一键领取",true,1,2) then
            w.click(40,40,2)
        end
        if w.fc("主界面-接授任务",true,1,3) then
            w.fc("主界面-自动任务",true)
            w.fc("主界面-自动任务-顺序",true)
            w.fc("主界面-自动任务-开始",true)
        end
        
        --转动一下视角
        task_jump_times = task_jump_times or 0
        task_jump_times = task_jump_times + 1
        if task_jump_times % 5 == 0 then
            w.d("主界面-任务-跳高",true,1,0.2)
            w.d("主界面-任务-跳高",true)
        end
        
        task_times = task_times or 1
        task_times = task_times + 1
        if task_times%2 == 0 then
            w.click(667,284)
            w.delay(5)
        end
    end
end


t['日常任务-推荐战力']={ {{754,251,0x7ebe79},{754,246,0x7ebe79}}, degree , 662,199,792,649}
    t['日常任务-接受任务-按钮']={ 0xb3d6d4, "22|2|0xb3d6d4,-51|-3|0xb3d6d4,-50|-3|0x2c3c59", 90, 1126, 217, 1323, 738}
    t['日常任务-接受任务-按钮2']={0xb3d6d4, "0|0|0xb3d6d4,0|7|0xb3d6d4,2|4|0x263554,-1|-18|0x263554,1|19|0x263554",degree,1200,201,1240,749}
    
    t['日常任务-自动执行按钮']={0xc2c4cc, "0|0|0xc2c4cc,-4|-24|0x4693ae,-1|23|0x4dadd1",degree,1200,201,1240,749}

t['日常任务-正在自动执行任务']={{1110, 239, 0x61afd8},{1115, 234, 0x61afd8},{1071, 238, 0xfdfdff},{1071, 255, 0xdddddd}}

t['日常任务-当前地图任务完成']={ 0x1a2336, "0|0|0x1a2336,39|-5|0x697d7e,83|0|0x6e8382,83|-3|0x1a2336,127|-2|0x6e8382,140|1|0x1a2336",degree , 1123,223,1324,304}
t['日常任务-当前任务无法自动完成']={ 0x7b7d83, "0|0|0x7b7d83,4|-2|0x14171d,136|3|0x888a8f,136|1|0x14171d",degree , 628,213,801,248}

function day_task()
    if w.mc("日常任务-正在自动执行任务") then
        w.delay(30)
        return 
    end
    
    
    w.click(1112,37)  --点开任务
    
    local i = 0
    local days_key = false
    while i < 10 do
        if w.fc('提示-返回') then
            days_key = true
            break
        end
        i = i+1
        w.delay(1)
    end
    
    if days_key then
        days_times = days_times + 1
    end
    
    if days_key and w.fc("日常任务-推荐战力") and days_times < 31 then
        local task_i = 0
        w.fc("提示-一键领取",true,1,3)
        while (w.d('日常任务-接受任务-按钮',true) or w.d("日常任务-接受任务-按钮2",true) ) and task_i < 3 do
            task_i = task_i + 1
        end
        w.fc("主界面-自动任务",true)
        w.d("日常任务-自动执行按钮",true)
        w.fc("主界面-自动任务-顺序",true)
            if w.d('日常任务-当前任务无法自动完成') then
                w.d("弹窗-任务x",true)
                ui.days = 'off'
            end
        w.fc("主界面-自动任务-开始",true)
    end
end


t['委托-移动']={ 0xb3d6d4, "0|0|0xb3d6d4,-1|-2|0x263554",degree , 1188,93,1258,704}
    t['委托-问号']={ 0xefefef, "0|0|0xefefef,1|-8|0x511f05,-16|23|0x742802,16|24|0x752a02",degree , 253,5,1029,564}
t['弹窗-委托-接受委托']={ 0xaec2de, "0|0|0xaec2de,0|-3|0x263554,-59|-5|0x263554,83|-5|0x263554",degree,558,533,1000,617}
    
t['委托-委托未激活']={ 0xc9bcac, "0|0|0xc9bcac,47|3|0xf3c598",degree , 1056,223,1128,260}
t['委托-委托激活']={ 0x68a4ff, "0|0|0x68a4ff,0|-1|0x6cadff",degree , 1288,233,1330,276}
--自动委托
function entrust()
    
    if w.d("委托-委托激活") or w.d("委托-委托未激活",true) then
        w.delay(10)
        return 
    end
    
    entrust_times = entrust_times or 0
    entrust_times = entrust_times + 1
    w.click(1112,37)  --点开任务
    
    local i = 0
    entrust_key = false
    while i < 10 do
        if w.fc('提示-返回') then
            w.click(367,31,2)
            entrust_key = true
            break
        end
        i = i+1
        w.delay(1)
    end
    
    if entrust_key then
        if w.fc("日常任务-推荐战力") and entrust_times < 31 then
            w.d("委托-移动",true,1,3)
            local i = 0
            while i < 100 do
                if w.d('委托-问号',true) then
                elseif w.fc("弹窗-点击对话",true)then
                elseif w.d('弹窗-委托-接受委托',true,1)then
                    break
                end
                w.delay(1)
                i = i + 1
            end
        else
            w.log('暂时没有委托')
            ui.entrust = 'off'
        end
    end
end

t['提示-有提示']={ {{1245,12,0xe27720},{1248,24,0xe27720}}, degree , 1233,7,1257,29}
t['提示-关闭提示']={ {{1226,102,0xffffff}}, degree , 1222,99,1229,106}
t['提示-一键领取']={ {{1169,175,0xbde5e4},{1231,175,0xd2fbf8},{1159,157,0x2c4e60},{1160,187,0x2c5066}}, degree , 1098,116,1311,225}
t['提示-成就-一键领取']={ 0xbde5e4, "0|0|0xbde5e4,5|-5|0x2c4c5d",degree , 1158,96,1273,121}
    t['提示-退出']={ {{1296,31,0xe9e9e9},{1305,20,0x030a13},{1305,40,0x030912},{1309,30,0xebebeb}}, degree , 1273,2,1325,59}
t['提示-确认取消']={ {{567,497,0xdeaeae},{754,498,0xadc1dd}}, degree , 483,448,852,536}

t['提示-返回']={ {{42,29,0x3f5ca5},{27,29,0xffffff},{47,19,0xffffff},{47,42,0xffffff},{46,35,0x3f5ba3}}, degree , 12,8,80,52}
    t['提示-成就']={ {{776,238,0x2cade8},{778,238,0x1a2339}}, degree , 765,232,781,249}
    t['提示-每日课题']={ {{116,150,0xebe8a7},{113,156,0x394036},{141,142,0xe5da7f}}, degree , 87,125,153,183}
       t['提示-每日课题-click']={{1214, 174, 0x5d808a},{664, 175, 0x1b1716},{1021, 175, 0x201410}}
    t['提示-解除封印']={ {{271,99,0xc0c5cf},{284,108,0x151f2f},{271,116,0xb9bec8},{271,104,0x212a3a}}, degree , 244,82,299,131}
        t['提示-解除封印-click']={{658, 110, 0x54688d},{855, 217, 0x7e9e48},{851, 217, 0x8c6028},{851, 217, 0x8c6028},{851, 217, 0x8c6028},{955, 218, 0x5c523a},{954, 215, 0x4f4d65},{1053, 222, 0xd5bd94},{1053, 222, 0xd5bd94}}
t['提示-属性鉴定']={ {{1296,30,0xebebeb},{1201,668,0xdda56c},{1204,727,0xf6e8af}}, degree , 1082,9,1323,739}
    t['提示-技能学习']={ 0xdfb176, "0|0|0xdfb176,-1|-31|0xdda56c,1|28|0xf6e8af",degree,836,658,1153,736}
    t['提示-召唤精灵']={ 0xaecdde, "0|0|0xaecdde,5|-28|0x579aa9,-4|31|0x6ed7dd",degree,1108,657,1314,735}
    
function 提示()
    if w.fc("提示-有提示") then
        tips_times = tips_times or 0
        tips_times = tips_times+1
        if tips_times%2 == 0 then
            moveTo(802,293,989,406)
        end
        
        w.click(1231,34,2)    --点开提示
        w.click(884,103,2)    --点开奖励
        local i = 0
        while i < 10 do
            if w.fc('提示-返回') then
                break
            end
            i = i+1
            w.delay(1)
        end
        
        if w.fc("提示-成就") then
            w.click(1185,110)
        elseif w.d("提示-成就-一键领取",true) then
        elseif w.fc("提示-每日课题") then
            w.table_click(t['提示-每日课题-click'])
        elseif w.fc("提示-解除封印") then
            w.table_click(t['提示-解除封印-click'])
        elseif w.fc("提示-一键领取",true,1,3)  or w.d("提示-技能学习",true)  then
            w.fc("提示-确认取消",true)
            w.click(40,40,2)
        elseif w.d('提示-召唤精灵',true,1,3)then
            jinling = {{863, 128, 0x616668},{960, 133, 0x7a7f80}}
            w.click( jinling[w.rd(1,2)][1],128 )
        else
            w.fc("提示-退出",true,1,3)
            w.click(1231,34)
            w.fc("提示-关闭提示",true)
            w.click(1231,34)
        end
        w.fc("提示-退出",true)
        return true
    end
end


t['战力-提示']={ {{1293,35,0xebebeb},{1307,28,0xe17620}}, degree , 1283,14,1316,42}
t['战力-提示-感叹号']={ {{1012,209,0xffffff},{1003,213,0xe27720},{1020,213,0xe27720}}, degree , 957,61,1320,684}

t['战力-提示-加号']={ {{1296,92,0xfefefd},{1291,92,0xf2e9e3},{1301,92,0xf6efea},{1306,92,0xe27720},{1287,92,0xe27720},{1296,101,0xe27720}}, degree , 959,69,1321,670}
t['战力-提示-小加号']={ {{1118,206,0xffffff},{1121,203,0xe27720},{1121,209,0xe27720},{1115,209,0xe27720},{1115,203,0xe27720},{1113,206,0xffffff},{1122,206,0xffffff}}, degree , 956,154,1321,728}

t['战力-返回界面']={ {{25,29,0xffffff},{42,30,0x3f5ca5},{50,21,0xffffff},{59,30,0x405da4}}, degree , 6,4,89,55}
    t['战力-返回界面-修炼']={ {{1050,698,0xdfdfdf},{1056,668,0xdda56c},{1060,727,0xf6e8af}}, degree , 981,642,1154,745}
--加战力

t['主界面-血条']={{17, 40, 0xb71213},{17, 41, 0xb20e0f}}
t['主界面-血条2']={{16, 38, 0xbf3132}}

function UI()
    if w.mc('主界面-血条') or w.mc('主界面-血条2') then
        return '主界面'
    end
end

t['主线-激活战斗']={ {{406,687,0xfefefe},{395,676,0xffffff},{405,697,0xb9b7b2}}, degree , 374,661,427,709}
t['主界面-帮助开封']={ 0x99a3ae, "0|0|0x99a3ae,5|-8|0xe27720",degree , 204,90,233,115}



function change_mpas_kuang()
    maps_arr = {
            ['0'] = { '银杏谷',{{566, 667, 0xc1c591},{504, 377, 0x5a6073}} },
            ['1'] = { '1比奇秘谷1层',{{1130, 646, 0xfff22a},{86, 94, 0x667aaf},{555, 242, 0x8b507e}}  },
            ['2'] = { '1比奇秘谷2层',{{1130, 646, 0xfff22a},{286, 93, 0x4b63a1},{632, 267, 0xa8a24e}} },
            ['3'] = { '1比奇秘谷3层',{{1130, 646, 0xfff22a},{483, 92, 0x4b4079},{537, 281, 0xaa436e}} },
            ['4'] = { '1比奇秘谷4层',{{1130, 646, 0xfff22a},{669, 95, 0xb4bbcd},{653, 426, 0x575e6e}} },
            ['5'] = { '银杏谷',{{566, 667, 0xc1c591},{504, 377, 0x5a6073}} },
            ['6'] = { '1比奇县',{{751, 277, 0x818279},{360, 438, 0x575d6b}} },
            ['7'] = { '半兽古墓1层',{{1107, 158, 0xc9a069},{299, 341, 0x2e9f64}} },
        }
        
    -- w.log( maps_arr[ui.maps][1] )
    mapsNmae = ocrMaps()
    
    -- w.log('mapsNmae-->'..mapsNmae )
    if mapsNmae == maps_arr[ui.maps][1]  then
            w.delay(2)
            return true
    else
        w.click(1171,104,4) --点开地图
        w.click(193, 30,3)
        for k,v in ipairs(maps_arr[ui.maps][2]) do
            w.click( v[1],v[2],2 )
            if k == #v then
                w.click( v[1],v[2],1 )
                w.delay(5)
            end
        end
    end
end


function change_maps()
    if w.fc("主界面-正在跑路") then
        w.delay(10)
        return 
    end
    
    level = ocrLevel()
    if type(level) == 'number' and level < ui.level then
        -- 如果小于16级,就去做主线
        task_main()
    else
        maps_arr = {
            ['0'] = { '原地',{{566, 667, 0xc1c591},{504, 377, 0x5a6073}} },
            ['1'] = { '比奇秘谷1层',{{1130, 646, 0xfff22a},{86, 94, 0x667aaf},{555, 242, 0x8b507e}}  },
            ['2'] = { '比奇秘谷2层',{{1130, 646, 0xfff22a},{286, 93, 0x4b63a1},{632, 267, 0xa8a24e}} },
            ['3'] = { '比奇秘谷3层',{{1130, 646, 0xfff22a},{483, 92, 0x4b4079},{537, 281, 0xaa436e}} },
            ['4'] = { '比奇秘谷4层',{{1130, 646, 0xfff22a},{669, 95, 0xb4bbcd},{653, 426, 0x575e6e}} },
            ['5'] = { '银杏谷',{{566, 667, 0xc1c591},{504, 377, 0x5a6073}} },
            ['6'] = { '比奇县',{{751, 277, 0x818279},{360, 438, 0x575d6b}} },
            ['7'] = { '半兽古墓1层',{{1107, 158, 0xc9a069},{299, 341, 0x2e9f64}} },
        }
        
        -- w.log( maps_arr[ui.maps][1] )
        mapsNmae = ocrMaps()
        
        -- w.log('mapsNmae-->'..mapsNmae )
        if ui.maps == '0' or string.find(mapsNmae,maps_arr[ui.maps][1]) then
            if w.mc("主界面-主线任务-正在战斗") then
                w.delay(60)
            else
                w.fc("主线-激活战斗",true,1,3)
            end
        else
            
            w.click(1171,104,4) --点开地图
            w.click(193, 30,3)
            for k,v in ipairs(maps_arr[ui.maps][2]) do
                w.click( v[1],v[2],2 )
                if k == 2 then
                    w.click( v[1],v[2],1 )
                    w.delay(30)
                end
            end
        end
    end
end

t['奖励-有提示']={ 0x8c98ae, "0|0|0x8c98ae,11|-17|0xe27720,15|-20|0xffffff",degree , 78,85,118,122}
    t['奖励-挑战-有提示']={ 0xffffff, "0|0|0xffffff,65|-12|0xe27720,73|-18|0xffffff",degree , 407,172,1183,261}
        t['奖励-挑战-有提示-2层提示']={0x2a4d87, "0|0|0x2a4d87,31|-14|0xe27720,37|-20|0xffffff",degree,463,256,1175,297}
        t['奖励-挑战-奖励领取']={ 0xaad0d8, "0|0|0xaad0d8,68|-20|0xe27720,74|-24|0xffffff",degree , 975,276,1190,674}
        t['奖励-挑战-全部领取']={ 0xaec2de, "0|0|0xaec2de,-30|-4|0x263554,84|-4|0x263554",degree , 1013,584,1187,627}
    t['奖励-挑战-左侧提示']={ 0x11141b, "0|0|0x11141b,142|-26|0xe27720,149|-30|0xffffff",degree , 194,87,382,676}
        t['奖励-28日签到']={ 0xfffdf9, "0|0|0xfffdf9,3|0|0xf7da93,80|10|0xe89a68",degree , 438,116,579,160}
            --478,254-107
        t['奖励-7日签到']={ 0xa5b9d5, "0|0|0xa5b9d5,9|33|0x667fb6,6|-166|0x7b9ae1",degree , 414,392,1186,635}
        t['奖励-7日签到-黄']={ 0xa5b9d5, "0|0|0xa5b9d5,4|-166|0xebd08d,12|33|0xccb67a",degree , 414,399,1189,633}
        t['奖励-购买提示']={ 0x263554, "0|0|0x263554,4|-3|0xb6bed0,26|-21|0xe27720,33|-26|0xffffff",degree,453,384,564,555}
        t['奖励-等级达到']={ 0xaec2de, "0|0|0xaec2de,3|1|0x263554,1|-22|0x263554,-610|2|0x58ff77",degree,423,215,1173,647}
        
--每日奖励
function day_award()
    w.d("主界面-帮助开封",true)
    if w.d('奖励-有提示',true,1,3)then
        function click_award()
            awrads = { '奖励-购买提示', '奖励-挑战-奖励领取','奖励-挑战-有提示','奖励-7日签到','奖励-7日签到-黄','奖励-28日签到',"奖励-等级达到",'奖励-挑战-左侧提示'}
            for k,v in ipairs(awrads) do
                if w.d(v,true) then
                    if v == '奖励-28日签到' then
                        for i=0,6 do
                            for ii = 0,3 do
                                -- if w.d('奖励-28日签到') then
                                w.click( 478+i*107, 254+ii*107, 0.3 )
                                -- end
                            end
                        end
                        w.d('奖励-挑战-左侧提示',true)
                    elseif v == "奖励-挑战-有提示" then
                        w.d("奖励-挑战-有提示-2层提示",true)
                        w.d("奖励-挑战-奖励领取",true)
                        w.d("奖励-挑战-全部领取",true)
                    end
                    return true
                end
            end
        end
        local i = 0
        while i < 30 and 
        (
            click_award()
        )
        do
            i=i+1
        end
        return true
    end
end

t['主界面-挖矿未激活']={0xffffff, "0|0|0xffffff,11|13|0xb6bab7,11|17|0xa8aea8",degree,312,673,343,704}
t['主界面-auto挖矿']={0xffffff, "0|0|0xffffff,15|16|0x3294a1,14|16|0xd2e0e5",degree,296,654,358,717}
    t['主界面-正在挖矿']={0x89f389, "0|0|0x89f389,0|-3|0x89f389,0|-18|0x65cedd",degree,558,493,570,525}
    t['主界面-正在反击']={0xffffff, "0|0|0xffffff,10|-2|0xffffff,-3|12|0xffffff,13|12|0xffffff",degree,376,578,426,627}

function game()
    other_record = 0
    days_times = 0
    while (true) do
        if w.active(_app.game,6) then
            setUI = UI()
            if setUI == '主界面' then
                other_record = 0
                if ui.task ~= '2' and day_award() then
                
                elseif 提示() then
                    --有提示先
                else
                    --采矿的设置
                    if ui.task == '2' then
                        kuangTimes = kuangTimes or 0
                        kuangTimes = kuangTimes + 1
                        
                        if w.d("主界面-正在反击") or w.d("主界面-正在挖矿") or w.d("主界面-auto挖矿") or w.d('主界面-挖矿未激活',true)   then
                            w.delay(10)
                        else
                            if kuangTimes%3== 0 and ui.maps ~= '0' then
                                if change_mpas_kuang() then
                                    w.log('正确的地图')
                                else
                                    moveTo(802,293,989,406)
                                    w.delay(2)
                                end
                            end
                        end
                    --开始了委托优先
                    elseif ui.entrust == 'on' then
                        entrust()
                    --每日任务开启
                    elseif ui.days == 'on' then
                        w.log('准备开始任务')
                        day_task()
                    else
                        change_maps()
                    end
                end
            else
                events =  event()
                if events then
                    if tips() then
                        if guard()then
                            other_record = other_record + 1
                            if other_record % 100 == 0 then
                                closeApp( _app.game ,1)
                                w.delay(3)
                            elseif other_record % 5== 0 then
                                w.click(40,40)
                            end
                        end
                    end
                end
            end
        end
        w.delay(1)
        w.log("~")
    end
end


require('ui')
ui.level = tonumber(ui.level)
w.log( ui )

    -- {
    --     ["task"] = "1",  主线,野外,采矿
    --     ["days"] = "on",     日常任务
    --     ["entrust"] = "on",      委捼任务
    --     ["maps"] = "0",  银杏谷,比奇城,比奇县,半兽古墓,半兽人遗迹,比奇迷宫,牛魔迷宫,牛魔神殿,沃玛森林,比奇秘谷
    -- }
    


game()
-- str = "wenhong520@qq.com"
-- str = "AaDd112211@"
-- str = "f3436ed4-541f-4a4b-a538-6a42ba3b608b"
-- inputText(str)





